# 文件读写

# mode : r代表读，  w代表覆盖写，  a代表追加写
file = open("students.txt", mode="r", encoding="utf-8")

# 读取所有数据
# print(file.read())


# 读取所有行
lines = file.readlines()

for line in lines:
    # 默认会读取换行符，strip去点前后空格
    print(line.strip())

file1 = open("test.txt", "a", encoding="utf-8")
for line in lines:
    file1.write(line.strip())
    file1.write("\n")

file1.close()

#  自动关闭io流,  当代码块结束后会自动关闭流
with open("students.txt", "r", encoding="utf-8") as f:
    print(f.readlines())
